package com.hmdp.controller;


import com.hmdp.dto.Result;
import com.hmdp.entity.BlogComments;
import com.hmdp.service.IBlogCommentsService;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 虎哥
 * @since 2021-12-22
 */
@RestController
@RequestMapping("/blog-comments")
public class BlogCommentsController {

    @Autowired
    private IBlogCommentsService blogCommentsService;

    //发评论
    @PostMapping("/comment/{shopId}")
    public Result blogComment(@PathVariable(value = "shopId")long shopId, @RequestBody BlogComments blogComments){
        // 传入blogId、content
        return blogCommentsService.blogComment(blogComments, shopId);
    }

    //改善发评论，url路径增加一个blog.userId，以便将评论推送至探店博文发表者的收件箱中
    @PostMapping("/comment/{shopId}/{blogUserId}")
    public Result blogComment2(@PathVariable(value = "shopId")long shopId,
                               @PathVariable(value = "blogUserId")long blogUserId,
                               @RequestBody BlogComments blogComments){
        // 传入blogId、content
        return blogCommentsService.blogComment(blogComments, shopId, blogUserId);
    }

    //获取探店博文的热点评论
    @GetMapping("/comment/get/{blogId}")
    public Result getBlogComments(@PathVariable(value = "blogId")long blogId){
        return blogCommentsService. getBlogComments(blogId);
    }

    //获取用户的评论消息
    @GetMapping("/of/message")//注意这里，因为第一次查询第一页时，请求中只带最小时间戳，没有偏移量，因此偏移量需要设默认值或者required = flase
    public Result getBlogCommentsMessage(@RequestParam(value = "lastId", required = true)Long minTime
            , @RequestParam(value = "offset", defaultValue = "0")Integer offset){
        return blogCommentsService.getBlogCommentsMessage(minTime,offset);
    }
}
